<html>
<head>
<title>管理系统</title>
<meta http-equiv=Content-Type content=text/html;charset=utf-8>
<#include "../inc/commonJs.html">
<script type="text/JavaScript">
var windowparam = '', grid;
//页面加载  
$(function(){ 
	/*
	var url = window.top.$('#tabs').tabs('getSelected').find('iframe').get(0).src;
	var flag;
	if(url.indexOf('?flag=')!=-1){
		flag = url.substring(url.lastIndexOf('?flag=')+6,url.length);
	}*/
	//加载数据  
    grid = $('#projectgrid').datagrid({  
        url:'listTask.do',  
        loadMsg:'数据加载中请稍后……',  
        pagination: true,  
        rownumbers: true,   
        striped: true,  
        singleSelect : true,  
        pageSize: [${syscfg.pageSize!10}],
        pageList: [${syscfg.pageList!10}],
         columns:[[  
             {field:'taskid',title: 'ID',align: 'center',width: '50'},  
             {field:'name',title: '任务名称',align: 'center',width: '200'},
             {field:'projectname',title: '所属项目',align: 'center',width: '150'},
             {field:'creatorname',title: '创建人',align: 'center',width: '100'},
             {field:'workername',title: '主执行人',align: 'center',width: '100'},
             {field:'starttime',title: '开始时间',align: 'center',width: '150'},
             {field:'stoptime',title: '结束时间',align: 'center',width: '150'},
             {field:'zt',title: '状态',align: 'center',width: '80',
             	formatter: function(value,rowdata,index){
             		var str = '<select id="zt_'+index+'" class="easyui-combobox" value='+value+' onchange="changeState(this,'+index+')" style="width:75px;" panelHeight="100px">'
             		if(value == 0){
             			str	+= '<option value="0" selected="true">未开始</option>'
             		}else{
             			str	+= '<option value="0" >未开始</option>'
             		}
             		if(value == 1){
             			str	+= '<option value="1" selected="true">进行中</option>'
             		}else{
             			str	+= '<option value="1" >进行中</option>'
             		}
             		if(value == 2){
             			str	+= '<option value="2" selected="true">完成</option>'
             		}else{
             			str	+= '<option value="2" >完成</option>'
             		}
             		if(value == 3){
             			str	+= '<option value="3" selected="true">待完成</option>'
             		}else{
             			str	+= '<option value="3" >待完成</option>'
             		}
             		str +='</select>'
					return str;
				}
             },
            // {field:'demo',title: '说明',align: 'center',width: '210'},
         ]],
         toolbar : ["-", btn_add, btn_edit, btn_del,"-"],
		onDblClickCell: function(rowIndex,rowData){
			//var taskid =  $('#projectgrid').datagrid('getData').rows[rowIndex].taskid;
			var taskid = $('#projectgrid').datagrid('getSelected').taskid;
			var ah = document.body.clientHeight;
			var aw = document.body.scrollWidth;
			var modalwindow = window.top.modalwindow('${request.contextPath}/xadmin/work/taskLogManage.do?taskid='+taskid,'',{    
		    width:aw,    
		    height:ah,
		    modal:true,
		    resizable:true,
		    title:'任务日志',
		    buttons:[{
				text:'关闭',
				iconCls:"icon-cancel",
				handler:function(){
					modalwindow.dialog('close');
				}
			}]   
		});
		}

     });
     $("#tree").tree({
            method: "post",
            lines: true,
            url: "${request.contextPath}/xadmin/work/listProjectForTree.do",
            dataPlain: true,       //该属性用以启用当前 easyui-tree 控件对平滑数据格式的支持
            toggleOnClick: false,
            enableContextMenu: false,
            onClick: function(node){
            	var params = {};
            	windowparam = node.id;
				params['projectId'] = node.id;
				$('#projectgrid').datagrid('reload',params); 
			}
    });
});  
	function doAdd() {
		var modalwindow = window.top.modalwindow('${request.contextPath}/xadmin/work/taskWindow.do?windowparam='+windowparam,$('#projectgrid'),{    
		    width:450,    
		    height:420,
		    modal:true,
		    resizable:true,
		    title:'新增项目信息',
		    buttons:[{
				text:'保存',
				iconCls:"icon-save",
				handler:function(){
					modalwindow.find('iframe').get(0).contentWindow.saveProject('',$('#tree'));
				}
			},{
				text:'关闭',
				iconCls:"icon-cancel",
				handler:function(){
					modalwindow.dialog('close');
				}
			}]   
		});
	}
	//
	function doEdit() {
		var selected = $('#projectgrid').datagrid('getSelected');
		if(!selected){
			window.top.$.messager.alert('提示',"请选择相关数据进行操作！");
			return;
		}
		var worker = selected.worker;
		var taskid = selected.taskid;
		var creator = selected.creator;
		if(worker != ${userInfo.userid!} && creator != ${userInfo.userid!}){
			window.top.$.messager.alert('提示',"你不是该任务执行人，无权限修改！");
			return;
		}
		var modalwindow =  window.top.modalwindow('${request.contextPath}/xadmin/work/taskWindow.do?taskid='+selected.taskid,$('#projectgrid'),{    
		    width:450,    
		    height:360,
		    modal:true,
		    resizable:true,
		    title:'修改项目信息',
		    buttons:[{
				text:'保存',
				iconCls:"icon-save",
				handler:function(){
					modalwindow.find('iframe').get(0).contentWindow.saveProject(selected.taskid,$('#tree'));
				}
			},{
				text:'关闭',
				iconCls:"icon-cancel",
				handler:function(){
					modalwindow.dialog('close');
				}
			}]   
		});
	}
	//
	function doDel(){
		var selected = $('#projectgrid').datagrid('getSelected');
		if(!selected){
			window.top.$.messager.alert('提示',"请选择相关数据进行操作！");
			return;
		}
		window.top.$.messager.confirm('系统提示', '<br>&nbsp;&nbsp;&nbsp;&nbsp;你确定要删除该信息?', function(r) {
			if (r) {
				$.post("${request.contextPath}/xadmin/work/delTask.do", { "taskid": selected.taskid},
				   function(data){
				   	$('#projectgrid').datagrid('reload'); 
				   	window.top.$.messager.alert('提示',data);
				   	
				});
			}
		});
	}
	//
	function changeState(_obj,_index){
		var worker = $('#projectgrid').datagrid('getData').rows[_index].worker;
		var taskid = $('#projectgrid').datagrid('getData').rows[_index].taskid;
		if(worker != ${userInfo.userid!}){
			window.top.$.messager.alert('提示',"你不是该任务执行人，无权限修改状态！");
			$('#zt_'+_index).val($('#taskLoggrid').datagrid('getData').rows[_index].zt);
			return;
		}
		$.post("${request.contextPath}/xadmin/work/updateTaskState.do", { "result": "zt="+$(_obj).val(),"taskid":taskid},
		   function(data){
		   	$('#projectgrid').datagrid('reload'); 
		   	window.top.$.messager.alert('提示',data);
		});
	}
</script>

</head>
<body class="easyui-layout">
<div data-options="region:'west',iconCls:'icon-mini-add',title:'按项目查找',split:true" style="width:180px;">
	<div class="easyui-panel" data-options='fit:true,border:false'> 
		<ul id="tree"></ul>
	</div>
</div>   
<div data-options="region:'center'">
<table id="projectgrid" data-options="fit:true,border:false"></table>
</div>  
</body>
</html>